Skip to content

Add cross-property BM25 And operator - #2114

Open
amourao wants to merge 1 commit into
dev/1.39from
worktree-bm25-search-mode
Open

Add cross-property BM25 And operator#2114
amourao wants to merge 1 commit into
dev/1.39from
worktree-bm25-search-mode

Conversation

@amourao

@amourao amourao commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Exposes the OPERATOR_AND_CROSS search operator (Weaviate 1.39.0, backported to 1.37.15 and 1.38.8) as BM25Operator.and_cross(), available wherever a BM25 operator is accepted: query.bm25, query.hybrid, the generative-query equivalents, and aggregate.hybrid.

Unlike and_(), which requires every query token to occur within a single property, and_cross() lets a token be matched by any of the searched properties as long as each token is matched by at least one. All searched properties must share the same tokenization and analyzer settings — the server rejects the query otherwise.

collection.query.bm25("banana split", operator=wvc.query.BM25Operator.and_cross())

Changes

  • BM25OperatorAndCross + BM25Operator.and_cross() in weaviate/collections/classes/grpc.py.
  • The duplicated SearchOperatorOptions construction in the bm25 and hybrid paths is folded into _BaseGRPC._bm25_operator_to_grpc(), so the version gate covers every caller. Using and_cross() against an older server raises WeaviateUnsupportedFeatureError rather than sending an enum value the server does not understand.
  • _ServerVersion.is_at_least_any() expresses a minimum that was backported across several release branches (a 1.38.x server needs 1.38.8, a 1.37.x server needs 1.37.15).
  • Regenerated protos for the OPERATOR_AND_CROSS enum value.
  • CI's 1.39 image bumped to 1.39.0-rc.1-89299a5 — the first RC carrying the operator.

Tests

  • test/collection/test_bm25_operator.py — operator-to-gRPC wiring for bm25/hybrid/aggregate-hybrid, and the version gate across supported and unsupported versions.
  • test/test_server_version.pyis_at_least_any() around each branch boundary.
  • Integration tests for cross-property matching against per-property and_ and or_, the mismatched-tokenization server error, and the unsupported-version path. All version-gated with skips.

Exposes the OPERATOR_AND_CROSS search operator added in Weaviate 1.39.0
(backported to 1.37.15 and 1.38.8) as `BM25Operator.and_cross()`. Unlike
`and_()`, a query token may be matched by any of the searched properties
instead of having to occur within a single one.

The gRPC construction for the bm25 and hybrid paths is folded into a shared
`_BaseGRPC._bm25_operator_to_grpc()` so the version gate applies to query,
generative-query and aggregation alike; sending the new enum to a server that
predates it raises WeaviateUnsupportedFeatureError.

`_ServerVersion.is_at_least_any()` is added to express minimums that were
backported across several release branches.
@amourao
amourao requested a review from a team as a code owner July 31, 2026 14:59

@orca-security-eu orca-security-eu Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.35484% with 7 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (dev/1.39@ae327ca). Learn more about missing BASE report.

Files with missing lines Patch % Lines
integration/test_collection.py 85.18% 4 Missing ⚠️
integration/test_collection_hybrid.py 81.25% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             dev/1.39    #2114   +/-   ##
===========================================
  Coverage            ?   88.29%           
===========================================
  Files               ?      303           
  Lines               ?    23397           
  Branches            ?        0           
===========================================
  Hits                ?    20659           
  Misses              ?     2738           
  Partials            ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants